
var check1='0';
var money="30";
var reg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
var account = $api.getStorage('account');

apiready = function(){
   
    var lnav = $api.domAll(".amount");
    for(var i in lnav){
        $api.addEvt(lnav[i], 'click', function(){
			for (var i = 0; i < lnav.length; i++) {
				$api.removeCls(lnav[i], 'active');
			}
			 
			$api.addCls(this,'active');    
             
			var mid=$api.attr(this, 'id');
            var div = $api.byId(mid);
            money = div.getAttribute("value");
        });   
    }
    
};


function recharge(){
	var payType=$api.val($api.dom('input[name="payType"]:checked'));
    
    var mobile = $api.byId('mobile').value;

    if(!reg.test(mobile)){
    	api.alert({msg:'请输入有效的手机号码'});
    	return;
	}
	
	if(!account){
		var date = new Date(); 
		account = '游客'+date.getFullYear()+(date.getMonth()+1)+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds();
	}
	
	var data = {
	     'mobile':mobile,
	     'goodname':money,
	     'account':account,
	     'payType':payType,
	     'source':api.systemType
	};
	
	console.log(JSON.stringify(data));
	
	do_ajax('/app/mobile/applyorder_new','post',data,function(ret,err){
		api.hideProgress();
		
		if(err){
			alert(err.code+ 'msg:' + err.msg);
		}
		else{
			if(ret.resultCode != 0){
				alert(ret.data);
			}
			else{
				var orderinfo = {
					orderNo: ret.orderNo,
					total: money,
					payType: payType,
				};
				
			   api.openWin({
			        name: 'pay',
			        url: "../pay.html",
			        pageParam: {orderinfo:orderinfo},
			   });
			}
		}
	});
}


